package dev.ece.suit.hexmap;

import java.util.ArrayList;
import java.util.List;

public class MapModelChunk {
	
	private MapModel model;
	
	private List<MapCell> cells;
	
	private List<MapCrevice> crevices;
	
	private List<MapTriangle> triangles;
	
	private List<MapWater> waters;
	
	private MapCellVAO mapCellVAO;
	
	private MapCreviceVAO mapCreviceVAO;
	
	private MapTriangleVAO mapTriangleVAO;
	
	private MapWaterVAO mapWaterVAO;
	
	private MapModelChunk(int rounds) {
		int size = rounds * 6;
		cells = new ArrayList<MapCell>(size);
		crevices = new ArrayList<MapCrevice>(size * 3);
		triangles = new ArrayList<MapTriangle>(size * 2);
		waters = new ArrayList<MapWater>(size);
	}
	
	protected static MapModelChunk createMapModelChunk(
			int rounds, MapCellVAO mapCellVAO, MapCreviceVAO mapCreviceVAO, 
			MapTriangleVAO mapTriangleVAO, MapWaterVAO mapWaterVAO) {
		MapModelChunk chunk = new MapModelChunk(rounds);
		chunk.mapCellVAO = mapCellVAO;
		chunk.mapCreviceVAO = mapCreviceVAO;
		chunk.mapTriangleVAO = mapTriangleVAO;
		chunk.mapWaterVAO = mapWaterVAO;
		return chunk;
	}
	
	protected void renderDepthMap() {
		getMapCellVAO().bind();
		for(MapCell cell: getCells()) {
			cell.renderDepth(getModel());
		}
		getMapCreviceVAO().bind();
		for(MapCrevice crevice: getCrevices()) {
			crevice.renderDepth(getModel());
		}
		getMapTriangleVAO().bind();
		for(MapTriangle triangle: getTriangles()) {
			triangle.renderDepth(getModel());
		}
	}
	
	protected void renderCells(HexMapCellShader cellShader) {
		getMapCellVAO().bind();
		for(MapCell cell: getCells()) {
			cell.render(getModel(), cellShader);
		}
	}
	
	protected void renderDevices(HexMapCreviceShader creviceShader) {
		getMapCreviceVAO().bind();
		for(MapCrevice crevice: getCrevices()) {
			crevice.render(getModel(), creviceShader);
		}
	}
	
	protected void renderTriangles(HexMapTriangleShader triangleShader) {
		getMapTriangleVAO().bind();
		for(MapTriangle triangle: getTriangles()) {
			triangle.render(getModel(), triangleShader);
		}
	}
	
	protected void renderWaters(HexMapWaterShader waterShader) {
		getMapWaterVAO();
		for(MapWater water: getWaters()) {
			water.render(getModel(), waterShader);
		}
	}

	public MapCellVAO getMapCellVAO() {
		return mapCellVAO;
	}

	public MapCreviceVAO getMapCreviceVAO() {
		return mapCreviceVAO;
	}

	public MapTriangleVAO getMapTriangleVAO() {
		return mapTriangleVAO;
	}

	public MapWaterVAO getMapWaterVAO() {
		return mapWaterVAO;
	}

	public List<MapCell> getCells() {
		return cells;
	}

	public List<MapCrevice> getCrevices() {
		return crevices;
	}

	public List<MapTriangle> getTriangles() {
		return triangles;
	}

	public List<MapWater> getWaters() {
		return waters;
	}

	public MapModel getModel() {
		return model;
	}
	
}
